<?php

namespace App\Api;

use App\Http\Controllers\Controller;
use App\Models\Template;
use TemplateService;
use Illuminate\Http\Request;
use DB;

class TemplateController extends Controller
{
    public function index()
    {
        TemplateService::init();
        $templates = Template::all();
        return $templates;
    }

    public function choose(Request $request)
    {
        DB::table('templates')->update(['installed' => false]);
        $template = Template::where('id', $request->id)->first();
        $template->installed = true;
        $template->save();
        return $this->message('模板设置成功');
    }
}
